const axios = require('axios');
const https = require('https');

module.exports = function (baseURL) {
  const username = process.env.API_USER_NAME;
  const password = process.env.API_PASSWORD;
  const cert = process.env.API_CERT;
  const key = process.env.API_KEY;
  const passphrase = process.env.API_PASSPHRASE;
  const timeout = process.env.PING_TIMEOUT;
  const auth = Buffer.from(`${username}:${password}`, 'ascii').toString('base64');
  const client = axios.create({
    baseURL,
    headers: { Authorization: `Basic ${auth}` },
    httpsAgent: new https.Agent({
      key,
      cert,
      passphrase,
      rejectUnauthorized: false,
    }),
    timeout: timeout,
  });
  return client;
};

